package com.qf.smartplatform.websocket;




import com.qf.smartplatform.events.CommandEvent;
import org.springframework.stereotype.Controller;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;

import java.io.IOException;


@Controller
public class MyCommandHandler extends MyBaseCommandHandler {

    public static void sendControl(CommandEvent event) {
        Object command = event.getCommand();
        String uid = event.getUid();
        WebSocketSession session = getAllClients().get(uid);//根据设备的id来获取到链接
        if (session != null && session.isOpen()) {
            try {
                session.sendMessage(new TextMessage(command.toString()));//发送命令
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
